package jmind.core.spring;

import java.beans.PropertyEditorSupport;
import java.util.Date;

import jmind.core.util.DataUtil;
import jmind.core.util.DateUtil;

/**
 * 
 * @author xieweibo
 * @see org.springframework.beans.propertyeditors.CustomDateEditor
 */
public class CustomDateEditor extends PropertyEditorSupport {

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        if (!DataUtil.isEmpty(text)) {
            if (text.length() > 8 && DataUtil.isNumber(text)) {
                setValue(new Date(DataUtil.toLong(text)));
            } else {
                setValue(DateUtil.parse(text));
            }

        }
    }

}
